package cn.hengzhu.main_manager.utils.shiro.realm;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import cn.hengzhu.main_manager.repository.dao.ManagePermissionMapper;
import cn.hengzhu.main_manager.repository.domain.ManagePermission;
import cn.hengzhu.main_manager.repository.domain.ManagePermissionExample;




/**
 * 构建过滤器链定义的映射
 *    url--过滤器名称
 * @author Administrator
 *
 */
public class FilterChainDefinitionMapFactoryBean {

	@Autowired
	private ManagePermissionMapper managePermissionMapper;
	/**
	 * 构建映射关系,把原来写死映射关系通过java类写活
	 * @return
	 */
	public Map<String, String> buildFilterChainDefinitionMap() {
		
		//LinkedHashMap//放的顺序和获取的顺序一致
		Map<String, String> result = new LinkedHashMap<String, String>();
		// <!-- 匿名访问资源放行 -->
		
		result.put("/msm/*", "anon");
		result.put("/openApiToInner/*", "anon");
		result.put("/openApi/*", "anon");
		result.put("/a846a07226cfdde696141c45fabe8352.html", "anon");
		result.put("/wxCommonxcx/*", "anon");
		result.put("/alixcxCommon/*", "anon");
		result.put("/alixcx/*", "anon");
		result.put("/shdeyusaahuiu.p12", "anon");
		result.put("/xcx/*", "anon");
		result.put("/bindingResult", "anon");
		result.put("swagger-resources", "anon");
		result.put("/MP_verify_MZl8D7go5VqfZ5E1.txt", "anon");
		result.put("/binder", "anon");
		result.put("/binder.jsp", "anon");
		result.put("/weixin/open/*", "anon");
		result.put("/public.js", "anon");
		result.put("/open.jsp", "anon");
		result.put("openerr.jsp", "anon");
		result.put("opened.jsp", "anon");
		result.put("/jump", "anon");
		result.put("/boxList", "anon");
		result.put("/login.jsp", "anon");
		result.put("/main/login/index", "anon");
		result.put("/resources/**", "anon");
		result.put("/main/getBoxInfo", "anon");
		result.put("/main/setBoxInfo", "anon");
		// <!-- 注销 -->
		result.put("/logout", "logout");
		// <!-- 权限拦截 ,那些资源要做权限拦截,以后就在这儿写 -->
		//获取要拦截所有的资源及其权限
		ManagePermissionExample example=new ManagePermissionExample();
		example.createCriteria().andIsShowEqualTo((byte)1);
		List<ManagePermission> permissionList= managePermissionMapper.selectByExample(example);
		for (ManagePermission permission : permissionList) {
			if (permission != null) {
			//  3 使用声明过自定义过滤器
				result.put(permission.getResource(), "managerPerms["+permission.getSn()+"]");
			}
		}
		// <!-- 都需要登录验证 -->
		result.put("/**", "authc");
		return result;
	}
}
